package de.laures.cewolf.tooltips;

import java.util.Arrays;
import java.util.List;

public class TableToolTip implements ToolTip {
	private String tt;
	private String title;
	private boolean isCtrlLock;
	private String[] names;
	private String[] values;

	public TableToolTip() {
	}

	public TableToolTip(String title, boolean isCtrlLock, String tt) {
		this();
		this.title = title;
		this.isCtrlLock = isCtrlLock;
		this.tt = tt;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public boolean isCtrlLock() {
		return isCtrlLock;
	}

	public void setCtrlLock(boolean isCtrlLock) {
		this.isCtrlLock = isCtrlLock;
	}

	public String[] getNames() {
		return names;
	}

	public void setNames(String... names) {
		this.names = names;
	}

	public Object[] getValues() {
		return values;
	}

	public void setValues(Object... values) {
		List list = Arrays.asList(values);
		setValues(list);
	}

	public String getTt() {
		return tt;
	}

	public void setValues(Object obj) {
		if (obj != null) {
			if (obj instanceof List) {
				List list = (List) obj;
				this.values = new String[list.size()];
				for (int i = 0; i < list.size(); i++) {
					this.values[i] = list.get(i).toString();
				}
			}
		}
	}

	public String getToolTipString() {
		StringBuilder sb = new StringBuilder();
		sb.append("tooltip(").append(tt).append(",'").append(this.title).append("',");
		for (String str : this.values) {
			sb.append("'").append(str).append("',");
		}
		if (sb.toString().endsWith(",")) {
			sb.deleteCharAt(sb.length() - 1);
		}
		sb.append(")");
		return sb.toString();
	}

}
